/*
 * Order.java
 *
 * Created on 8 May 2007, 11:52
 * Copyright (C) 2007   Yuezhong Zhang
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package usyd.comp5348;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity class Order
 *
 * @author Yuezhong Zhang
 */
@Entity(name="OrderTable")
public class Order implements Serializable {
    public static final int PENDING = 1;
    public static final int SUBMITTED = 2;
    public static final int ACCEPTED = 3;
    public static final int DELIVERED = 4;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    
    /** Creates a new instance of Order */
    public Order() {
    }
    
    /**
     * Gets the id of this Order.
     * @return the id
     */
    public Integer getId() {
        return this.id;
    }
    
    /**
     * Sets the id of this Order to the specified value.
     * @param id the new id
     */
    public void setId(Integer id) {
        this.id = id;
    }
    
    /**
     * Returns a hash code value for the object.  This implementation computes
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }
    
    /**
     * Determines whether another object is equal to this Order.  The result is
     * <code>true</code> if and only if the argument is not null and is a Order object that
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Order)) {
            return false;
        }
        Order other = (Order)object;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;
        return true;
    }
    
    /**
     * Returns a string representation of the object.  This implementation constructs
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "usyd.comp5348.Order[id=" + id + "]";
    }
    
    /**
     * Holds value of property customerId.
     */
    @Column(name="customerId")
    private int customerId;
    
    /**
     * Getter for property customerId.
     * @return Value of property customerId.
     */
    public int getCustomerId() {
        return this.customerId;
    }
    
    /**
     * Setter for property customerId.
     * @param customerId New value of property customerId.
     */
    public void setCustomerId(int customerId) {
        this.customerId = customerId;
    }
    
    /**
     * Holds value of property total.
     */
    @Column(name="total")
    private float total;
    
    /**
     * Getter for property total.
     * @return Value of property total.
     */
    public float getTotal() {
        return this.total;
    }
    
    /**
     * Setter for property total.
     * @param total New value of property total.
     */
    public void setTotal(float total) {
        this.total = total;
    }
    
    /**
     * Holds value of property videos.
     */
    @OneToMany(fetch=FetchType.EAGER,mappedBy = "orderId",cascade={CascadeType.ALL})
    private Collection<OrderLine> videos;
    
    /**
     * Getter for property videos.
     * @return Value of property videos.
     */
    public Collection<OrderLine> getVideos() {
        return this.videos;
    }
    
    /**
     * Setter for property videos.
     * @param videos New value of property videos.
     */
    public void setVideos(Collection<OrderLine> videos) {
        this.videos = videos;
    }
    
    /**
     * Holds value of property orderDate.
     */
    @Column(name="orderDate")
    @Temporal(value = TemporalType.DATE)
    private Date orderDate;
    
    /**
     * Getter for property orderDate.
     * @return Value of property orderDate.
     */
    public Date getOrderDate() {
        return this.orderDate;
    }
    
    /**
     * Setter for property orderDate.
     * @param orderDate New value of property orderDate.
     */
    public void setOrderDate(Date orderDate) {
        this.orderDate = orderDate;
    }
    
    /**
     * Holds value of property warehouse.
     */
    @Column(name="warehouse")
    private String warehouse;
    
    /**
     * Getter for property warehouse.
     * @return Value of property warehouse.
     */
    public String getWarehouse() {
        return this.warehouse;
    }
    
    /**
     * Setter for property warehouse.
     * @param warehouse New value of property warehouse.
     */
    public void setWarehouse(String warehouse) {
        this.warehouse = warehouse;
    }
    
    /**
     * Holds value of property store.
     */
    @Column(name="store")
    private String store;
    
    /**
     * Getter for property store.
     * @return Value of property store.
     */
    public String getStore() {
        return this.store;
    }
    
    /**
     * Setter for property store.
     * @param store New value of property store.
     */
    public void setStore(String store) {
        this.store = store;
    }
    
    /**
     * Holds value of property status.
     */
    @Column(name="status")
    private int status;
    
    /**
     * Getter for property status.
     * @return Value of property status.
     */
    public int getStatus() {
        return this.status;
    }
    
    /**
     * Setter for property status.
     * @param status New value of property status.
     */
    public void setStatus(int status) {
        this.status = status;
    }
    
}
